package com.miracle.设计模式.结构型模式.代理模式.静态代理;


import com.miracle.设计模式.结构型模式.代理模式.IHttpInvoke;

public class HttpInvokeProxy implements IHttpInvoke {
    private IHttpInvoke iHttpInvoke;

    public HttpInvokeProxy(IHttpInvoke iHttpInvoke) {
        this.iHttpInvoke = iHttpInvoke;
    }

    /**
     * 代理方法
     */
    @Override
    public String invoke(String request) {
        request = this.before(request);
        String response = iHttpInvoke.invoke(request);
        response = this.after(response);
        return response;
    }

    /**
     * 前置处理
     */
    private String before(String request){
        request = request + "^_^";
        System.out.println("服务端代理获取到请求(前置加工)："+ request);
        return request;
    }

    /**
     * 后置处理
     */
    private String after(String response){
        response = response + "-_-";
        System.out.println("服务端代理获取到响应(后置加工)："+ response);
        return response;
    }
}
